<template>
  <el-card shadow="never">
    <div slot="header" class="card-header">
      <span>审计报告</span>
      <el-button type="primary" @click="exportExcel()">下载</el-button>
    </div>
    <el-table id="out-table" :data="tableData" border style="width: 100%">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="columnA" label="审计省份（分公司）">
      </el-table-column>
      <el-table-column prop="columnB" label="是否风险"> </el-table-column>
      <el-table-column prop="columnC" label="是否问责"> </el-table-column>
      <el-table-column prop="columnD" label="所审计年份"> </el-table-column>
      <el-table-column prop="columnE" label="审计时间"> </el-table-column>
    </el-table>
    <div class="pagination">
      <Pagination />
    </div>
  </el-card>
</template>

<script>
import Pagination from './Pagination'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
export default {
  components: {
    Pagination
  },

  data() {
    return {
      tableData: [
        {
          columnA: '浙江',
          columnB: '是',
          columnC: '否',
          columnD: '2019',
          columnE: '2020.2'
        },
        {
          columnA: '广东',
          columnB: '是',
          columnC: '否',
          columnD: '2019',
          columnE: '2020.2'
        },
        {
          columnA: '新疆',
          columnB: '是',
          columnC: '否',
          columnD: '2019',
          columnE: '2020.3'
        },
        {
          columnA: '辽宁',
          columnB: '是',
          columnC: '否',
          columnD: '2019',
          columnE: '2020.1'
        },
        {
          columnA: '四川',
          columnB: '是',
          columnC: '否',
          columnD: '2019',
          columnE: '2020.3'
        }
      ]
    }
  },

  methods: {
    exportExcel() {
      /* out-table关联导出的dom节点  */
      var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))
      /* get binary string as output */
      var wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        bookSST: true,
        type: 'array'
      })
      try {
        FileSaver.saveAs(
          new Blob([wbout], { type: 'application/octet-stream' }),
          '审计报告.xlsx'
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.log(e, wbout)
      }
      return wbout
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination {
  float: right;
  margin: 10px;
}
</style>
